package com.zsgeek.wisdchain.qutu.view.home;

import android.os.Bundle;
import android.view.KeyEvent;

import com.journeyapps.barcodescanner.CaptureManager;
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
import com.zsgeek.wisdchain.qutu.BaseActivity;
import com.zsgeek.wisdchain.qutu.R;

/**
 * 二维码扫描
 */
public class ScanQrCodeActivity extends BaseActivity {
    DecoratedBarcodeView mDBV;
    private CaptureManager captureManager;     //捕获管理器


    @Override
    public int getLayoutId() {
        return R.layout.activity_scan_qr_code;
    }

    @Override
    protected void initView() {
        setTitle(R.string.scan_qr_code);
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {
        mDBV = findViewById(R.id.dbv);
        captureManager = new CaptureManager(this, mDBV);
        captureManager.initializeFromIntent(getIntent(), savedInstanceState);
        captureManager.decode();

        mDBV.setStatusText(getString(R.string.scan_two_dimensional_code_from_viewfinder));

    }

//    @Override
//    protected boolean isDarkStatusBar() {
//        return false;
//    }

    @Override
    protected void onPause() {
        super.onPause();
        captureManager.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        captureManager.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mDBV = null;
        captureManager.onDestroy();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        captureManager.onSaveInstanceState(outState);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return mDBV.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
    }
}
